package com.wenjh.jdmzt.service.dao;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.wenjh.jdmzt.service.model.Image;

public class ImageDao extends BaseDao<Image, String> implements Image.Table {

	public ImageDao(SQLiteDatabase db) {
		super(db, TableName, F_ImageId);
	}

	@Override
	public void insert(Image t) {
		insert(new String[] {
			F_ImageId,
			F_Support,
			F_Type,
			F_Unsupport,
			F_Url
		}, new Object[]{
			t.getId(),
			t.getSupportCount(),
			t.getType(),
			t.getUnsupportCount(),
			t.getUrlString()
		});
	}

	@Override
	public void update(Image t) {
		updateField(new String[]{
				F_Support,
				F_Type,
				F_Unsupport,
				F_Url
		}, new Object[]{
				t.getSupportCount(),
				t.getType(),
				t.getUnsupportCount(),
				t.getUrlString()
		}, new String[]{
				F_ImageId
		}, new Object[]{
				t.getId(),
		});
	}

	@Override
	public void deleteInstence(Image obj) {
		delete(obj.getId());
	}
	
	@Override
	protected void assemble(Image image, Cursor cursor) {
		image.setId(cursor.getString(cursor.getColumnIndex(F_ImageId)));
		image.setSupportCount(cursor.getInt(cursor.getColumnIndex(F_Support)));
		image.setType(cursor.getInt(cursor.getColumnIndex(F_Type)));
		image.setUnsupportCount(cursor.getInt(cursor.getColumnIndex(F_Unsupport)));
		image.setUrlString(cursor.getString(cursor.getColumnIndex(F_Url)));
	}

	@Override
	protected Image assemble(Cursor cursor) {
		Image image = new Image();
		assemble(image, cursor);
		return image;
	}

}
